<!-- 会员 - 餐厅充值单- 组件 -->
<template>
  <div>
    <div class="bill-card-box" :class="selectRechargeOrderData ? 'show' : 'hide'">
      <div v-if="loading" class="skeleton-container">
        <div class="skeleton-title"></div>
        <div class="skeleton-desc"></div>
        <div class="skeleton-item" v-for="n in 8" :key="n"></div>
      </div>
      <div v-else>
        <div class="title">{{ rechargeTicketDetailData.shopName }}</div>
        <div class="desc">【充值单】</div>
        <div class="desc-item">
          <div>会员卡号：</div>
          <span>{{ rechargeTicketDetailData.vipNumber }}</span>
        </div>
        <div class="desc-item">
          <div>会员手机号：</div>
          <span>{{ rechargeTicketDetailData.phone }}</span>
        </div>
        <div class="desc-item">
          <div>会员名称：</div>
          <span>{{ rechargeTicketDetailData.vipName }}</span>
        </div>
        <div class="desc-item">
          <div>余额：</div>
          <span>{{ rechargeTicketDetailData.balance }}</span>
        </div>
        <div class="desc-item">
          <div>积分：</div>
          <span>{{ rechargeTicketDetailData.integral }}</span>
        </div>
        <div class="split-line"></div>
        <div class="desc-item">
          <div>充值金额（本金）：</div>
          <span>{{ rechargeTicketDetailData.money }}</span>
        </div>
        <div class="desc-item">
          <div>充值类型：</div>
          <span>{{ rechargeTicketDetailData.type }}</span>
        </div>
        <div class="desc-item">
          <div>支付方式：</div>
          <!-- <div v-for="(item, index) in rechargeTicketDetailData.payList" :key="index">
            <div v-if="item.pay_method === 'cash'">现金支付</div>
            <div v-else-if="item.pay_method === 'balance'">会员支付</div>
            <div v-else>{{ item.pay_method }}</div>
          </div> -->
          <div>
            <template v-if="rechargeTicketDetailData.payList.length > 1">混合支付</template>
            <template v-else>
              {{
                rechargeTicketDetailData.payList.length && rechargeTicketDetailData.payList[0].name
              }}
            </template>
          </div>
        </div>
        <template v-if="rechargeTicketDetailData.payList.length > 1">
          <div
            class="desc-item"
            v-for="(item, index) in rechargeTicketDetailData.payList"
            :key="index"
          >
            <div>{{ item.name }}</div>
            <span>{{ item.money }}</span>
          </div>
        </template>
        <div class="split-line"></div>
        <div class="desc-item">
          <div>收银员：</div>
          <span>{{ rechargeTicketDetailData.cashier }}</span>
        </div>
        <!-- <div class="desc-item">
          <div>营销员：</div>
          <span>XD22152025420</span>
        </div> -->
        <div class="desc-item">
          <div>流水号：</div>
          <span>{{ rechargeTicketDetailData.serialNumber }}</span>
        </div>
        <div class="desc-item">
          <div>客户签名：</div>
          <span></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, watch } from 'vue'
import { rechargeOrderDetailTicket } from '@/api/member'
import { dealAssignDataFunction, fetchObjectDeepAttrValue } from '@/utils/toolsValidate'

// 定义props
const props = defineProps({
  selectedOrderData: {
    type: Object,
    default: null
  }
})

// 响应式数据
const rechargeTicketDetailData = ref({
  vipNumber: '',
  phone: '',
  vipName: '',
  balance: '',
  integral: '',
  money: '',
  type: '',
  payList: [],
  cashier: '',
  serialNumber: '',
  shopName: ''
})
const loading = ref(false)

// 计算属性
const selectRechargeOrderData = computed(() => props.selectedOrderData)

// 监听选中的预订id变化
watch(
  () => selectRechargeOrderData.value?.order_id,
  newV => {
    if (newV) {
      getDeskBookTicketDetail(newV)
    }
  },
  { immediate: true, deep: true }
)

// 获取预订小票数据
const getDeskBookTicketDetail = id => {
  loading.value = true
  const datas = {
    order_id: id
  }
  rechargeOrderDetailTicket(datas)
    .then(res => {
      if (res.status === 200) {
        const detailData = dealAssignDataFunction(null, res?.data?.detail)
        rechargeTicketDetailData.value.vipNumber = fetchObjectDeepAttrValue(
          detailData,
          'detail.userInfo.user_id',
          '无'
        )
        rechargeTicketDetailData.value.phone = fetchObjectDeepAttrValue(
          detailData,
          'detail.userInfo.mobile',
          '无'
        )
        rechargeTicketDetailData.value.vipName =
          fetchObjectDeepAttrValue(detailData, 'detail.userInfo.nick_name', '无') ||
          fetchObjectDeepAttrValue(detailData, 'detail.userInfo.real_name', '无')
        rechargeTicketDetailData.value.balance = fetchObjectDeepAttrValue(
          detailData,
          'detail.userInfo.balance',
          '0'
        )
        rechargeTicketDetailData.value.integral = fetchObjectDeepAttrValue(
          detailData,
          'detail.userInfo.points',
          '0'
        )
        rechargeTicketDetailData.value.money = fetchObjectDeepAttrValue(
          detailData,
          'detail.payInfo.pay_money',
          '0'
        )
        rechargeTicketDetailData.value.type = fetchObjectDeepAttrValue(
          detailData,
          'detail.planInfo.plan_name',
          '无'
        )
        rechargeTicketDetailData.value.payList = fetchObjectDeepAttrValue(
          detailData,
          'detail.payList',
          []
        )
        rechargeTicketDetailData.value.cashier = fetchObjectDeepAttrValue(
          detailData,
          'detail.clerkName',
          '无'
        )
        rechargeTicketDetailData.value.serialNumber = fetchObjectDeepAttrValue(
          detailData,
          'detail.orderInfo.order_no',
          '无'
        )
        rechargeTicketDetailData.value.shopName = fetchObjectDeepAttrValue(
          detailData,
          'detail.shopInfo.shop_name',
          '无'
        )
      }
    })
    .finally(() => {
      loading.value = false
    })
}
</script>

<style lang="scss" scoped>
.hide {
  display: none;
}
.show {
  display: block;
  width: 420px;
  transition: all 1s;
}
.minHeight {
  height: 720px;
}
.maxHeight {
  height: 984px;
}
.bill-card-box {
  height: 984px;
  width: 420px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 3px 0px 24px 0px rgba(0, 0, 0, 0.16);
  box-sizing: border-box;
  padding: 30px 30px 0 30px;
  .title {
    font-size: 20px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
  }
  .desc {
    font-size: 16px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
    margin: 10px 0;
  }
  .desc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    color: #333333;
    margin-top: 10px;
  }
  .split-line {
    width: 360px;
    height: 1px;
    background: #e2e2e2;
    margin-top: 10px;
  }
}

// 骨架屏样式
.skeleton-container {
  padding: 30px 30px 0 30px;

  .skeleton-title {
    width: 200px;
    height: 24px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin: 0 auto 10px;
  }

  .skeleton-desc {
    width: 100px;
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin: 0 auto 20px;
  }

  .skeleton-item {
    width: 100%;
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin-top: 10px;

    &:nth-child(3) {
      width: 80%;
    }
    &:nth-child(4) {
      width: 70%;
    }
    &:nth-child(5) {
      width: 85%;
    }
    &:nth-child(6) {
      width: 60%;
    }
    &:nth-child(7) {
      width: 90%;
    }
    &:nth-child(8) {
      width: 75%;
    }
    &:nth-child(9) {
      width: 65%;
    }
    &:nth-child(10) {
      width: 80%;
    }
  }
}

@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}
</style>
